const svgCaptcha = require("svg-captcha");

module.exports = router => {

    // create captcha
  router.get("/captcha", ctx => {
    var captcha = svgCaptcha.create(
        {
            height:60
        }
    );
    ctx.session.captcha = captcha.text;
    ctx.response.type = "image/svg+xml";
    ctx.body = captcha.data;
  });

  // check captcha
  

  router.get("/captcha/checkcaptcha",ctx=>{
          let{captcha}=ctx.request.query;
          let sessionCaptcha=ctx.session.captcha;
          if(sessionCaptcha==captcha){
              ctx.body="图片验证成功";
          }else{
              ctx.body="图片验证失败";
          }

  });
};
